#ifndef CSVSOPENCV_H
#define CSVSOPENCV_H

#include "svsclass.h"
#include <highgui.h>
#include <cv.h>
#include <cvaux.h>
#include "opencv2/gpu/gpu.hpp"

using namespace cv;
enum { STEREO_BM=0, STEREO_SGBM=1, STEREO_HH=2, STEREO_BP, STEREO_CSBP, STEREO_BMGPU };

class cSvsOpencv
{
	int resH;
	int resV;
	bool isColor;
	int stereoAlg;
	
	std::string extrinFileName;
	std::string intrinFileName;
	
	bool opened;
	bool started;
	
	svsVideoImages *videoObject;
	svsAcquireImages *sourceObject;
	svsStereoImage *si;
	
	IplImage* imgRight;
	IplImage* imgLeft;
	IplImage* headerRight;
	IplImage* headerLeft;
	
	Mat map11, map12, map21, map22;
    Rect roi1, roi2;
    StereoBM bm;
    StereoSGBM sgbm;
	
	cv::gpu::StereoBM_GPU *bmGPU;
	cv::gpu::StereoBeliefPropagation *bpm;
	cv::gpu::StereoConstantSpaceBP *csbpm;
	
	int SADWindowSize; 
	int numberOfDisparities;
	
	void initRetification();

public:
	cSvsOpencv(int aResH, int aResV, bool aColor, int aStereoAlgo = 0, const char * aExtrinFileName = NULL, const char * aIntrinFileName = NULL);
	bool Open();
	void Start();
	IplImage * getLeft();
	IplImage * getRight();
	void refresh();
	void setRes(int aResH, int aResV);
	void setColor(bool color);
	void setStereoAlgo(int alg);
	void setExtrinsicsFile(const char * aExtrinFileName);
	void setIntrisicsFile(const char * aIntrinFileName);
	void setSADWindowSize(int wSize);
	void setNumberOfDisparities(int nDisparities);
	IplImage * calculateStereo();
	void Stop();
	void Close();
	~cSvsOpencv();

};

#endif // CSVSOPENCV_H
